load(
    "@prelude//toolchains/android/tools:build_rules.bzl",
    "buck_java_binary",
    "buck_java_library",
    "buck_kotlin_library",
)
load("@prelude//utils:source_listing.bzl", "source_listing")

oncall("android_devxx")

source_listing()

HELPERS_SRCS = [
    "AdbHelper.java",
    "AdbOptions.java",
    "AdbExecutionContext.java",
    "AndroidInstallPrinter.java",
    "exopackage/ExoHelper.java",
    "exopackage/DexExoHelper.java",
    "exopackage/ExopackageInstaller.java",
    "exopackage/ExopackageMode.java",
    "exopackage/ExopackageUtil.java",
    "exopackage/NativeExoHelper.java",
    "exopackage/AdbUtils.kt",
    "exopackage/AndroidDeviceImpl.kt",
    "exopackage/ResourcesExoHelper.java",
]

buck_kotlin_library(
    name = "helpers",
    srcs = HELPERS_SRCS,
    tests = [
        "prelude//toolchains/android/test/com/facebook/buck/android:unit",
    ],
    visibility = [
        "PUBLIC",
    ],
    deps = [
        "prelude//toolchains/android/src/com/facebook/buck/android/device:device",
        "prelude//toolchains/android/src/com/facebook/buck/core/util/log:log",
        "prelude//toolchains/android/src/com/facebook/buck/installer/android:exceptions",
        "prelude//toolchains/android/src/com/facebook/buck/io/filesystem/impl:utils",
        "prelude//toolchains/android/src/com/facebook/buck/io/pathformat:pathformat",
        "prelude//toolchains/android/src/com/facebook/buck/util:process_executor",
        "prelude//toolchains/android/src/com/facebook/buck/util:util",
        "prelude//toolchains/android/src/com/facebook/buck/util/environment:environment",
        "prelude//toolchains/android/third-party:guava",
        "prelude//toolchains/android/third-party:kotlinx-coroutines-core-jvm",
        "prelude//toolchains/android/third-party:zstd-jni",
        ":manifest_utils",
        ":utils_api",
    ],
    exported_deps = [
    ],
)

MANIFEST_UTILS_SRCS = [
    "AndroidManifestReader.java",
    "AndroidManifestReaderExecutableMain.java",
    "DefaultAndroidManifestReader.java",
]

buck_java_binary(
    name = "manifest_utils_binary",
    main_class = "com.facebook.buck.android.AndroidManifestReaderExecutableMain",
    visibility = [
        "PUBLIC",
    ],
    deps = [
        ":manifest_utils",
    ],
)

buck_java_library(
    name = "manifest_utils",
    srcs = MANIFEST_UTILS_SRCS,
    tests = [
        "prelude//toolchains/android/test/com/facebook/buck/android:unit",
    ],
    visibility = [
        "PUBLIC",
    ],
    deps = [
        "prelude//toolchains/android/src/com/facebook/buck/util/xml:xml",
        "prelude//toolchains/android/third-party:args4j",
    ],
)

UTILS_API_SRCS = [
    "exopackage/AndroidDevicesHelper.java",
    "exopackage/IsolatedExopackageInfo.kt",
    "exopackage/AndroidDeviceInfo.kt",
    "exopackage/AndroidDevice.java",
    "exopackage/AndroidIntent.java",
    "IsolatedApkInfo.java",
    "exopackage/PackageInfo.java",
]

buck_kotlin_library(
    name = "utils_api",
    srcs = UTILS_API_SRCS,
    visibility = [
        "PUBLIC",
    ],
    deps = [
        "prelude//toolchains/android/src/com/facebook/buck/io/filesystem:filesystem",
        "prelude//toolchains/android/src/com/facebook/buck/util:util",
        "prelude//toolchains/android/src/com/facebook/buck/util/environment:platform",
        "prelude//toolchains/android/src/com/facebook/buck/util/xml:xml",
        "prelude//toolchains/android/third-party:guava",
    ],
)
